#Boa:Frame:Frame1

import wx,re,glob,os,Configure


from wx.lib.anchors import LayoutAnchors

DeviceNameInData=""        
SortTypesInData=["Sort1"]
LotNumInData=""
WaferIDInData=["01"]

DeviceNameInMapData=""        
SortTypesInMapData=["Sort1"]
LotNumInMapData=""

TestDataDir=r'D:/GUI'


def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1DATACONVERTSTATICBOX, 
 wxID_FRAME1DEVICENAMECHOICEINDATA, wxID_FRAME1DEVICENAMECHOICEINMAPDATA, 
 wxID_FRAME1DEVICENAMESTATICTEXTINDATA, 
 wxID_FRAME1DEVICENAMESTATICTEXTINMAPDATA, wxID_FRAME1GAUGEINDATA, 
 wxID_FRAME1LOTNUMBUTTONINDATA, wxID_FRAME1LOTNUMBUTTONINMAPDATA, 
 wxID_FRAME1LOTNUMSTATICTEXTINDATA, wxID_FRAME1LOTNUMSTATICTEXTINMAPDATA, 
 wxID_FRAME1LOTNUMTEXTCTRLINDATA, wxID_FRAME1LOTNUMTEXTCTRLINMAPDATA, 
 wxID_FRAME1MAPDATASTATICBOXINMAPDATA, wxID_FRAME1NOTEBOOK1, 
 wxID_FRAME1PANEL2, wxID_FRAME1PANEL3, wxID_FRAME1PANEL4, 
 wxID_FRAME1RECONFIGBUTTONINDATA, wxID_FRAME1SORTTYPERADIOBOXINDATA, 
 wxID_FRAME1SORTTYPERADIOBOXINMAPDATA, wxID_FRAME1STARTBUTTONINDATA, 
 wxID_FRAME1STARTBUTTONINMAPDATA, wxID_FRAME1TESTDATADIRBUTTONINCONFIGURATION, 
 wxID_FRAME1TESTDATADIRTEXTCTRLINCOFIGURATION, wxID_FRAME1TESTDIRSTATICTEXT, 
 wxID_FRAME1TITLDATASTATICTEXT, wxID_FRAME1VIEWBUTTONINMAPDATA, 
 wxID_FRAME1WAFERIDSTATICTEXTINDATA, wxID_FRAME1WAFERIDTEXTCTRLINDATA, 
] = [wx.NewId() for _init_ctrls in range(30)]

class Frame1(wx.Frame):
    def _init_coll_notebook1_Pages(self, parent):
        # generated method, don't edit

        parent.AddPage(imageId=-1, page=self.panel2, select=True,
              text=u'Manual Convert Data')
        parent.AddPage(imageId=-1, page=self.panel3, select=False,
              text=u'MapData Convert')
        parent.AddPage(imageId=-1, page=self.panel4, select=False,
              text=u'Configuration')

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(476, 408), size=wx.Size(593, 371),
              style=wx.STAY_ON_TOP | wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(585, 337))
        self.SetAutoLayout(True)
        self.Enable(True)

        self.notebook1 = wx.Notebook(id=wxID_FRAME1NOTEBOOK1, name='notebook1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(608, 336), style=0)

        self.panel2 = wx.Panel(id=wxID_FRAME1PANEL2, name='panel2',
              parent=self.notebook1, pos=wx.Point(0, 0), size=wx.Size(600, 309),
              style=wx.TAB_TRAVERSAL)
        self.panel2.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              u'Tahoma'))

        self.panel3 = wx.Panel(id=wxID_FRAME1PANEL3, name='panel3',
              parent=self.notebook1, pos=wx.Point(0, 0), size=wx.Size(600, 309),
              style=wx.TAB_TRAVERSAL)
        self.panel3.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              u'Tahoma'))

        self.panel4 = wx.Panel(id=wxID_FRAME1PANEL4, name='panel4',
              parent=self.notebook1, pos=wx.Point(0, 0), size=wx.Size(600, 309),
              style=wx.TAB_TRAVERSAL)
        self.panel4.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              u'Tahoma'))

        self.TestDirStaticText = wx.StaticText(id=wxID_FRAME1TESTDIRSTATICTEXT,
              label=u'TestDataDir:', name=u'TestDirStaticText',
              parent=self.panel4, pos=wx.Point(16, 24), size=wx.Size(105, 23),
              style=0)

        self.TestDataDirTextCtrlInCofiguration = wx.TextCtrl(id=wxID_FRAME1TESTDATADIRTEXTCTRLINCOFIGURATION,
              name=u'TestDataDirTextCtrlInCofiguration', parent=self.panel4,
              pos=wx.Point(128, 24), size=wx.Size(360, 24), style=0,
              value=u'D:\\GUI')
        self.TestDataDirTextCtrlInCofiguration.Bind(wx.EVT_TEXT,
              self.OnTestDataDirTextCtrlInCofigurationText,
              id=wxID_FRAME1TESTDATADIRTEXTCTRLINCOFIGURATION)

        self.TestDataDirButtonInConfiguration = wx.Button(id=wxID_FRAME1TESTDATADIRBUTTONINCONFIGURATION,
              label=u'...', name=u'TestDataDirButtonInConfiguration',
              parent=self.panel4, pos=wx.Point(488, 16), size=wx.Size(36, 34),
              style=0)
        self.TestDataDirButtonInConfiguration.Bind(wx.EVT_BUTTON,
              self.OnTestDataDirButtonInConfiguration,
              id=wxID_FRAME1TESTDATADIRBUTTONINCONFIGURATION)

        self.MapDataStaticBoxInMapData = wx.StaticBox(id=wxID_FRAME1MAPDATASTATICBOXINMAPDATA,
              label=u'Config', name=u'MapDataStaticBoxInMapData',
              parent=self.panel3, pos=wx.Point(16, 16), size=wx.Size(376, 256),
              style=0)

        self.DeviceNameStaticTextInMapData = wx.StaticText(id=wxID_FRAME1DEVICENAMESTATICTEXTINMAPDATA,
              label=u'DeviceName:', name=u'DeviceNameStaticTextInMapData',
              parent=self.panel3, pos=wx.Point(32, 48), size=wx.Size(111, 23),
              style=0)

        self.DeviceNameChoiceInMapData = wx.Choice(choices=["HED0205",
              "HED0302", "HED0405", "HED0409"],
              id=wxID_FRAME1DEVICENAMECHOICEINMAPDATA,
              name=u'DeviceNameChoiceInMapData', parent=self.panel3,
              pos=wx.Point(160, 48), size=wx.Size(208, 31), style=0)
        self.DeviceNameChoiceInMapData.SetHelpText(u'Select Device Name you want to convert data')
        self.DeviceNameChoiceInMapData.Bind(wx.EVT_CHOICE,
              self.OnDeviceNameChoiceInMapData,
              id=wxID_FRAME1DEVICENAMECHOICEINMAPDATA)

        self.LotNumStaticTextInMapData = wx.StaticText(id=wxID_FRAME1LOTNUMSTATICTEXTINMAPDATA,
              label=u'Lot    Num:', name=u'LotNumStaticTextInMapData',
              parent=self.panel3, pos=wx.Point(40, 216), size=wx.Size(104, 23),
              style=0)

        self.LotNumTextCtrlInMapData = wx.TextCtrl(id=wxID_FRAME1LOTNUMTEXTCTRLINMAPDATA,
              name=u'LotNumTextCtrlInMapData', parent=self.panel3,
              pos=wx.Point(160, 216), size=wx.Size(176, 31), style=0,
              value=u'')
        self.LotNumTextCtrlInMapData.Bind(wx.EVT_TEXT,
              self.OnLotNumTextCtrlInMapData,
              id=wxID_FRAME1LOTNUMTEXTCTRLINMAPDATA)

        self.LotNumButtonInMapData = wx.Button(id=wxID_FRAME1LOTNUMBUTTONINMAPDATA,
              label=u'...', name=u'LotNumButtonInMapData', parent=self.panel3,
              pos=wx.Point(336, 216), size=wx.Size(32, 34), style=0)
        self.LotNumButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnLotNumButtonInMapData,
              id=wxID_FRAME1LOTNUMBUTTONINMAPDATA)

        self.StartButtonInMapData = wx.Button(id=wxID_FRAME1STARTBUTTONINMAPDATA,
              label=u'Start', name=u'StartButtonInMapData', parent=self.panel3,
              pos=wx.Point(424, 56), size=wx.Size(92, 34), style=0)
        self.StartButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnStartButtonInMapData, id=wxID_FRAME1STARTBUTTONINMAPDATA)

        self.ViewButtonInMapData = wx.Button(id=wxID_FRAME1VIEWBUTTONINMAPDATA,
              label=u'View', name=u'ViewButtonInMapData', parent=self.panel3,
              pos=wx.Point(432, 184), size=wx.Size(92, 34), style=0)
        self.ViewButtonInMapData.Bind(wx.EVT_BUTTON, self.OnViewButtonInMapData,
              id=wxID_FRAME1VIEWBUTTONINMAPDATA)

        self.SortTypeRadioBoxInMapData = wx.RadioBox(choices=["Sort1", "Sort2",
              "Two Type"], id=wxID_FRAME1SORTTYPERADIOBOXINMAPDATA,
              label=u'Sort Type:', majorDimension=3,
              name=u'SortTypeRadioBoxInMapData', parent=self.panel3,
              point=wx.Point(32, 96), size=wx.DefaultSize,
              style=wx.RA_SPECIFY_COLS)
        self.SortTypeRadioBoxInMapData.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypeRadioBoxInMapData,
              id=wxID_FRAME1SORTTYPERADIOBOXINMAPDATA)

        self.TitlDataStaticText = wx.StaticText(id=wxID_FRAME1TITLDATASTATICTEXT,
              label=u'Manual Data Covert Tool', name=u'TitlDataStaticText',
              parent=self.panel2, pos=wx.Point(104, 24), size=wx.Size(316, 35),
              style=0)
        self.TitlDataStaticText.SetFont(wx.Font(22, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.DataConvertStaticBox = wx.StaticBox(id=wxID_FRAME1DATACONVERTSTATICBOX,
              label=u'Config:', name=u'DataConvertStaticBox',
              parent=self.panel2, pos=wx.Point(8, 72), size=wx.Size(448, 176),
              style=0)

        self.DeviceNameStaticTextInData = wx.StaticText(id=wxID_FRAME1DEVICENAMESTATICTEXTINDATA,
              label=u'DeviceName:', name=u'DeviceNameStaticTextInData',
              parent=self.panel2, pos=wx.Point(16, 104), size=wx.Size(111, 23),
              style=0)

        self.DeviceNameChoiceInData = wx.Choice(choices=['HED0302', 'HED0409'],
              id=wxID_FRAME1DEVICENAMECHOICEINDATA,
              name=u'DeviceNameChoiceInData', parent=self.panel2,
              pos=wx.Point(136, 104), size=wx.Size(200, 31), style=0)
        self.DeviceNameChoiceInData.Bind(wx.EVT_CHOICE,
              self.OnDeviceNameChoiceInData,
              id=wxID_FRAME1DEVICENAMECHOICEINDATA)

        self.SortTypeRadioBoxInData = wx.RadioBox(choices=['Sort1', 'Sort2'],
              id=wxID_FRAME1SORTTYPERADIOBOXINDATA, label=u'SortType:',
              majorDimension=1, name=u'SortTypeRadioBoxInData',
              parent=self.panel2, point=wx.Point(350, 85), size=wx.Size(100,
              105), style=wx.RA_SPECIFY_COLS)
        self.SortTypeRadioBoxInData.SetStringSelection(u'Sort1')
        self.SortTypeRadioBoxInData.SetThemeEnabled(True)
        self.SortTypeRadioBoxInData.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypeRadioBoxInData,
              id=wxID_FRAME1SORTTYPERADIOBOXINDATA)

        self.LotNumStaticTextInData = wx.StaticText(id=wxID_FRAME1LOTNUMSTATICTEXTINDATA,
              label=u'Lot      Num:', name=u'LotNumStaticTextInData',
              parent=self.panel2, pos=wx.Point(16, 152), size=wx.Size(108, 23),
              style=0)

        self.LotNumTextCtrlInData = wx.TextCtrl(id=wxID_FRAME1LOTNUMTEXTCTRLINDATA,
              name=u'LotNumTextCtrlInData', parent=self.panel2,
              pos=wx.Point(136, 152), size=wx.Size(176, 31), style=0,
              value=u'')
        self.LotNumTextCtrlInData.Bind(wx.EVT_TEXT, self.OnLotNumTextCtrlInData,
              id=wxID_FRAME1LOTNUMTEXTCTRLINDATA)

        self.LotNumButtonInData = wx.Button(id=wxID_FRAME1LOTNUMBUTTONINDATA,
              label=u'...', name=u'LotNumButtonInData', parent=self.panel2,
              pos=wx.Point(312, 152), size=wx.Size(28, 34), style=0)
        self.LotNumButtonInData.Bind(wx.EVT_BUTTON, self.OnLotNumButtonInData,
              id=wxID_FRAME1LOTNUMBUTTONINDATA)

        self.WaferIDTextCtrlInData = wx.TextCtrl(id=wxID_FRAME1WAFERIDTEXTCTRLINDATA,
              name=u'WaferIDTextCtrlInData', parent=self.panel2,
              pos=wx.Point(136, 200), size=wx.Size(304, 31), style=0,
              value=u'01;')
        self.WaferIDTextCtrlInData.Bind(wx.EVT_TEXT,
              self.OnWaferIDTextCtrlInData,
              id=wxID_FRAME1WAFERIDTEXTCTRLINDATA)

        self.WaferIDStaticTextInData = wx.StaticText(id=wxID_FRAME1WAFERIDSTATICTEXTINDATA,
              label=u'Wafer     ID:', name=u'WaferIDStaticTextInData',
              parent=self.panel2, pos=wx.Point(16, 200), size=wx.Size(107, 23),
              style=0)

        self.StartButtonInData = wx.Button(id=wxID_FRAME1STARTBUTTONINDATA,
              label=u'Start', name=u'StartButtonInData', parent=self.panel2,
              pos=wx.Point(472, 96), size=wx.Size(92, 34), style=0)
        self.StartButtonInData.Bind(wx.EVT_BUTTON, self.OnStartButtonInData,
              id=wxID_FRAME1STARTBUTTONINDATA)

        self.ReConfigButtonInData = wx.Button(id=wxID_FRAME1RECONFIGBUTTONINDATA,
              label=u'ReConfig', name=u'ReConfigButtonInData',
              parent=self.panel2, pos=wx.Point(472, 176), size=wx.Size(92, 34),
              style=0)
        self.ReConfigButtonInData.Bind(wx.EVT_BUTTON,
              self.OnReConfigButtonInData, id=wxID_FRAME1RECONFIGBUTTONINDATA)

        self.GaugeInData = wx.Gauge(id=wxID_FRAME1GAUGEINDATA,
              name=u'GaugeInData', parent=self.panel2, pos=wx.Point(8, 264),
              range=100, size=wx.Size(560, 28), style=wx.GA_HORIZONTAL)

        self._init_coll_notebook1_Pages(self.notebook1)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.MyInit()
    
    def MyInit(self):
        global TestDatadir
        
        InitiFile=open("InitSetting","r")
        for Line in InitiFile.readlines():
            if re.search(r'TestDataDir=',Line):
                Line=Line.strip()
                TempArray=re.split(r'=',Line)
                TestDataDir=TempArray[1] 
                self.TestDataDirTextCtrlInCofiguration.SetValue(TestDataDir)
                
        InitiFile.close      

    def OnDeviceNameChoiceInMapData(self, event):
        global DeviceNameInMapData
        DeviceNameInMapData=event.GetString()
        print DeviceNameInMapData

    def OnLotNumTextCtrlInMapData(self, event):
        LotNumInMapData=event.GetString()
        print LotNumInMapData

    def OnLotNumButtonInMapData(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",
                          style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInMapData
            #TempArray=re.split(r"\\",dlg.GetPath())
            LotNumInMapData=os.path.basename(dlg.GetPath())
            self.LotNumTextCtrlInMapData.SetValue(LotNumInMapData)
            #print LotNum 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()

    def OnStartButtonInMapData(self, event):
        if DeviceNameInMapData=="":
            dlg = wx.MessageDialog(self, 'Please Input DeviceName In MapData!',
                               'A Error Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
            dlg.ShowModal()
            dlg.Destroy()                   
        elif LotNumInMapData=="":
            dlg = wx.MessageDialog(self, 'Please Input LotNum In MapData!',
                               'A Error Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
            dlg.ShowModal()
            dlg.Destroy()   
        else:
            self.OnStatistics()

    def OnStatistics(self):
        global DataDir
        global DeviceNameInMapData
        global LotNumInMapData
        MapDir=os.path.join(TestDataDir,DeviceNameInMapData,LotNumInMapData , "/map")
        os.chdir(MapDir)
        files=glob.glob('*.map')
        
        for SortType in SortTypesInMapData:
            #OutFileName=LotNumInMapData + "_" + SortType + "_" + "mapdata.txt"
            OutFileName="".joine(LotNumInMapData , "_" ,SortType ,"_" ,"mapdata.txt")
            OutFile=open(OutFileName,"w")
            
            for file in files:
                PassDie=0
                TotalGoodDie=0
                if re.search(SortType,file):
                    MapFile=open(file)
                    Lines=MapFile.readlines()
                    for Line in Lines:
                        if re.search("\s+\d+\s+[\d+|\w+|\+]\s+\d+\s+\d+\.\d+%\s+PASS;",Line):
                            TempDatas=re.split("\s+",Line)
                            PassDie=int(TempDatas[3])                        
                            TotalGoodDie=TotalGoodDie+PassDie
                            
                    OutFile.write("%s : %d\n" % (file,PassDie))
                OutFile.write("Total Passed:  %d\n" % TotalGoodDie)
            OutFile.close           
            
    def OnViewButtonInMapData(self, event):
        global TestDataDir
        global DeviceNameInMapData
        global LotNumInMapData
        global SortTypesInMapData
        
        if DeviceNameInMapData=="":
            dlg = wx.MessageDialog(self, 'Please Input DeviceName In MapData!',
                               'A Error Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
            dlg.ShowModal()
            dlg.Destroy()                   
        elif LotNumInMapData=="":
            dlg = wx.MessageDialog(self, 'Please Input LotNum In MapData!',
                               'A Error Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
            dlg.ShowModal()
            dlg.Destroy()   
        else:
            #MapDir=TestDataDir+ "/" + DeviceNameInMapData + "/" + LotNumInMapData + "/map"
            MapDir=os.path.join(TestDataDir,DeviceNameInMapData,LotNumInMapData ,"map")
        
            for SortType in SortTypesInMapData:
                ViewFileName="".join((MapDir,"/" ,LotNumInMapData ,"_", SortType ,"_" ,"mapdata.txt"))
                Command="NotePad.exe  " + ViewFileName
                os.system(Command)

    def OnSortTypeRadioBoxInMapData(self, event):
        global SortTypesInMapData
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInMapData=["Sort2"]
        if SortTypeSelect==1:
            SortTypesInMapData=["Sort2"]    
        else :
            SortTypesInMapData=["Sort1","Sort2"]
                    
        print SortTypesInMapData

    def OnTestDataDirTextCtrlInCofigurationText(self, event):
        global TestDataDir
        if event.GetString()=="":
            dlg = wx.MessageDialog(self, 'The TestDataDir must not be empty In MapData!',
                               'A Error Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
            dlg.ShowModal()
            dlg.Destroy()   
        else:
            TestDataDir=event.GetString()
        print TestDataDir
    def OnTestDataDirButtonInConfiguration(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",
                          style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global TestDataDir            
            TestDataDir=dlg.GetPath()
            self.TestDataDirTextCtrlInCofiguration.SetValue(TestDataDir)
            
            InitFile = open("InitSetting","r+")
            InitFileOut= open("InitSettingOut","w")
            Flag=1
            for Line in InitFile.readlines():
                if re.search(r'TestDataDir=',Line):
                    InitFileOut.write("TestDataDir=%s\n" % TestDataDir)
                    Flag=0
                else :
                    InitFile.write(Line)
            if Flag:
                InitFileOut.write("TestDataDir=%s\n" % TestDataDir)
            InitFile.close
            InitFileOut.close
            del InitFile
            del InitFileOut
            os.remove("InitSetting")            
            os.renames("InitSettingOut","InitSetting")   
                
            #print LotNum 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()

    def OnDeviceNameChoiceInData(self, event):
        global DeviceNameInData
        DeviceNameInData=event.GetString()
        print DeviceNameInData

    def OnLotNumTextCtrlInData(self, event):
        global LotNumInData
        LotNumInData =event.GetString()
        print LotNumInData
        
    def OnLotNumButtonInData(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",
                          style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInData
            #TempArray=re.split(r"\\",dlg.GetPath())
            #LotNumInData=TempArray[len(TempArray)-1]
            LotNumInData=os.path.basename(dlg.GetPath())
            self.LotNumTextCtrlInData.SetValue(LotNumInData)
            #print LotNum 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()

    def OnSortTypeRadioBoxInData(self, event):
        global SortTypesInData
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInData=["Sort1"]
        elif SortTypeSelect==1:
            SortTypesInData=["Sort2"]
        
        print SortTypesInData        

    def OnWaferIDTextCtrlInData(self, event):
        global WaferIDInData
        TempData=event.GetString()
        if TempData=="":
            dlg = wx.MessageDialog(self, 'The WaferID must not be empty In MapData!\n The format is 01;02;...',
                               'A Error Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
            dlg.ShowModal()
            dlg.Destroy()
         
        TempArray=re.split(r";",TempData)
        TempFlag=0
        for Temp in TempArray:
            if re.search("\D+",Temp):
                TempFlag=1
                continue
            elif len(Temp)>0:
                if int(Temp)>25:
                    TempFlag=2
            else:
                TempArray.remove(Temp)        
                
        if TempFlag==1:
            dlg = wx.MessageDialog(self, 'There is some no digital in WaferID string In MapData! ',
                               'A Error Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
            dlg.ShowModal()
            dlg.Destroy()
        elif TempFlag==2:
            dlg = wx.MessageDialog(self, 'There is some wrong waferID(That is more than 25 In MapData!',
                               'A Error Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
            dlg.ShowModal()
            dlg.Destroy() 
            
        WaferIDInData=TempArray                                    
            

    def OnStartButtonInData(self, event):
        event.Skip()

    def OnReConfigButtonInData(self, event):
        global WaferIDInData
        global SortTypesInData
        global LotNumInData
        global DeviceNameInData
        
        self.WaferIDTextCtrlInData.SetValue("01;")
        WaferIDInData="01;"
        
        self.SortTypeRadioBoxInData.SetSelection(0)
        SortTypesInData=["Sort1"]
        
        self.LotNumTextCtrlInData.SetValue("")        
        LotNumInData=""
        
        self.DeviceNameChoiceInData.SetSelection(-1)
        DeviceNameInData=""
    
            
            
        
        
        
        
